package com.hmdp.utils;


import com.hmdp.dto.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
//    从java对象装为json.
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail(null);
    }


    @ExceptionHandler(HmdpException.class)
    @ResponseBody
    public Result Hmdperror(HmdpException e) {
        e.printStackTrace();
        System.out.println(e.toString());
        return Result.fail(e.getMessage());
    }

}
